package io.github.lee.core.util

import android.app.Activity
import android.os.Build


inline fun <reified T> Activity.getBundleParcelable(
    key: String,
    clazz: Class<T>
): T? {
    val args = intent.extras ?: return null

    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        args.getParcelable(key, clazz)
    } else {
        @Suppress("DEPRECATION")
        args.getParcelable(key)
    }
}

inline fun <reified T> Activity.getBundleValue(key: String, defaultValue: T?): T? {
    val bundle = intent.extras ?: return defaultValue
    val data = when (defaultValue) {
        is String -> bundle.getString(key, defaultValue)
        is Short -> bundle.getShort(key, defaultValue)
        is Int -> bundle.getInt(key, defaultValue)
        is Long -> bundle.getLong(key, defaultValue)
        is Float -> bundle.getFloat(key, defaultValue)
        is Double -> bundle.getDouble(key, defaultValue)
        is Byte -> bundle.getByte(key, defaultValue)
        is Char -> bundle.getChar(key, defaultValue)
        is Boolean -> bundle.getBoolean(key, defaultValue)
        else -> throw IllegalArgumentException("Unsupported data types")

    }
    return data as T


}
